home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 6.2 KB | 238 lines | [TEXT/LTLK] |
- %
- % File: FontProcs.ps
- %
- % Contains: This file contains Procedures the Used to do simple modifications of fonts.
- %
- % Version: Technology: Quickdraw GX 1.1.x.
- %
- % Copyright: © 1991-7 by Apple Computer, Inc., all rights reserved.
- %
- %
-
- % File contains the following Procedures:
- % MakeFontClone
- % MakeFramedFont
- % MakeBoldFont
- % MakeVerticalFont
-
- %<FF>
- %
- % Procedure: MakeFontClone
- %
- % Clones a font dictionary so we can change or add entries to it.
- %
- % baseFontDict N MakeFontClone cloneFontDict
- %
- % baseFontDict: A valid font dictionary
- % N: Number of dictionary entries to add.
- %
- /MakeFontClone {
-
- exch
- dup length 3 -1 roll add dict begin % Make dictionary big enough for new entries.
-
- % Duplicate all entries bug /FID and /UniqueID
- {
- 1 index /FID ne 2 index /UniqueID ne and {def} {pop pop} ifelse
- } forall
-
- currentdict
-
- end
-
- } Bdef
-
- %<FF>
- % Procedure: MakeFramedFont
- % Makes a frame-filled font from a base font
- % This is accomplished by changing the PaintType to 2
- % Of course, this would only work on fonts that obey this.
- % But we know that all fonts do, right?
- %
- % baseFontDict strokeWidth MakeFramedFont framedFontDict
- %
- % baseFontDict: A valid font dictionary
- % strokeWidth: Width of outline in user space for a 1 point character.
- % outlineFontDict: The new font dictionary, ready for definefont.
- %
- /MakeFramedFont {
-
- 1 index /FontType get 0 ne { % Terminal condition for recursive traversal of composite fonts.
-
- exch 2 MakeFontClone
- begin
- /PaintType 2 def % Change PaintType to 2.
- 0 FontMatrix idtransform pop % Run strokeWidth through Font's matrix.
- /StrokeWidth Xdef
- currentdict
- end
-
- } { % Traverse composite font recursively and make stroked base fonts.
-
- exch % Stack is: strokeWidth baseFontDict
- 0 MakeFontClone begin % Clone the composite font
-
- FDepVector length array % Make an array for the new FDepVector, leave on stack.
- 0 % Index for array insertion
-
- FDepVector { % Stack is: strokeWidth newArray index oldFDepEntry
-
- 3 index % Stack is: strokeWidth newArray index oldFDepEntry strokeWidth
- MakeFramedFont /FDepFramedFont
- exch definefont % Stack is: strokeWidth newArray index newFDepEntry
- 3 copy put pop % Stack is: strokeWidth newArray index, framed font in newArray.
- 1 add % Stack is: strokeWidth newArray index+1
-
- } forall
-
- pop % Stack is: strokeWidth newArray
- /FDepVector Xdef % Put new FDepVector in type-0 dictionary.
- pop % Pop off copy of strokeWidth
-
- currentdict % Leave the current dictionary on stack.
-
- end
-
- } ifelse
-
- } Bdef
-
-
- %<FF>
- % Procedure: MakeVerticalFont
- % Procedures changes the WMode entry of a font for vertical text
- %
- % baseFontDict MakeVerticalFont verticalFontDict
- %
- /MakeVerticalFont {
-
- dup /WMode known {0} {1} ifelse MakeFontClone
-
- dup begin
-
- /WMode 1 def
-
- end
-
- } Bdef
-
-
-
-
- %<FF>
- %
- % BuildChar procedure for the bold font.
- %
- % dict char BoldBuildChar
- %
- % dict: the bold font's font dictionary.
- % char: The character code from the base font to render.
- %
- % The Bold procedure draws a bold glyph as follows:
- % Stroke the path of the normal glyph with a non-square pen
- % Draw the normal glyph
- % This routine is to be called from a type-3 font with the character code on the stack
- % And the font dictionary at the top of the dictionary stack.
- %
- %
- /BoldBuildChar {
-
- exch begin
-
- theChar 0 3 -1 roll put % Put the character code into the string.
-
- baseFontDict setfont
-
- % Compute the new advance metric: Old advance + boldness
-
- theChar stringwidth % Get the advance widths of the normal character.
- dup 0 ne {yBold add} if % If the y advance wasn't zero, add the y bold.
- exch
- dup 0 ne {xBold add} if % IF the x advance wasn't zero, add the x bold.
- exch
-
-
- % First compute the bounding box of the bold glyph
-
- gsave
-
- newpath
- 0 0 moveto
- theChar false GXCharPath % Get the path of the character
-
- gsave
- % Get the bounding box of the non-square pen stroke
- xBold 2 mul yBold 2 mul scale 1 setlinewidth strokepath
- pathbbox
-
- grestore
-
- grestore
- setcachedevice
-
-
- % Now draw the bold glyph.
-
- newpath
- 0 0 moveto theChar true GXCharPath
- %
- % Stroke the path with a non-square pen using sneaky scaling method.
- %
- currentlinewidth % Save the current line width
- xBold 2 mul % Do scaling to get non-square pen.
- yBold 2 mul
- scale
- 1 setlinewidth % set line width to 1, so when run through
- % The scale, it becomes xBold, yBold.
- CharPathCount 0 eq {stroke} {strokepath} ifelse
-
- 1 xBold 2 mul div 1 yBold 2 mul div scale % undo the scaling
- setlinewidth % restore the current line width
-
- 0 0 moveto
- theChar CharPathCount 0 eq {show} {true charpath} ifelse
-
- end
-
- } Bdef
-
-
- %<FF>
- %
- % Procedure to make a bold font from a base font. However, these fonts cannot be used
- % in any context that requires the proper functioning of the charpath operator. Since
- % this font calls charpath and charpath is not re-entrant, it is not possible to call
- % charpath on this font. Adobe really screwed up this time.
- %
- % dict x y MakeBoldFont dict
- %
- % dict: the base font dictionary,.
- % x y: the x and y boldness values. (Amount to outset the glyphs)
- % dict: The new font dictionary for the bold font.
- %
- /MakeBoldFont {
-
- 20 dict dup begin % Create the new font dictionary, leave it on stack and dict stack.
- 4 1 roll % Put duplicate of dict ref behind parameters on stack.
-
- /yBold Xdef % Save the boldness values.
- /xBold Xdef
-
- /baseFontDict Xdef % Save the base font dictionary reference.
-
- /theChar 1 string def % Place for characters.
-
- baseFontDict /Encoding get /Encoding Xdef % Copy the base font's encoding.
- /FontType 3 def % New font will be type 3
- /FontMatrix [1 0 0 1 0 0] def % Don't muck with base font's coordinates.
- /FontBBox [0 0 0 0] def % This is safest.
-
- %
- % Now define the buildChar procedure.
- %
- /BuildChar /BoldBuildChar load def
-
- end
-
- } Bdef
-